#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
清理测试数据脚本
"""

import sqlite3
from config import Config

def clean_test_data():
    """清理测试数据"""
    print("🧹 清理测试数据...")
    
    with sqlite3.connect(Config.DATABASE_PATH) as conn:
        cursor = conn.cursor()
        
        # 删除测试数据
        cursor.execute("DELETE FROM templates WHERE name LIKE '%测试%' OR name LIKE '%演示%' OR name LIKE '%代理%'")
        cursor.execute("DELETE FROM regions WHERE template_id NOT IN (SELECT id FROM templates)")
        cursor.execute("DELETE FROM projects WHERE template_id NOT IN (SELECT id FROM templates)")
        
        conn.commit()
        
        # 显示剩余数据
        cursor.execute("SELECT COUNT(*) FROM templates")
        template_count = cursor.fetchone()[0]
        
        cursor.execute("SELECT COUNT(*) FROM regions")
        region_count = cursor.fetchone()[0]
        
        cursor.execute("SELECT COUNT(*) FROM projects")
        project_count = cursor.fetchone()[0]
        
        print(f"✅ 清理完成")
        print(f"   剩余底板: {template_count}")
        print(f"   剩余区域: {region_count}")
        print(f"   剩余项目: {project_count}")

if __name__ == '__main__':
    clean_test_data()
